package model

import "ginblog/utils/errmsg"

type Setup struct {
	BaseModel
	Desc         string `gorm:"type:varchar(32);comment:'简介'" json:"desc"`
	BlogIcon     string `gorm:"type:varchar(256);comment:'博客图标'" json:"blog_icon"`
	BlogName     string `gorm:"type:varchar(32);comment:'博客名称'" json:"blog_name"`
	RecordNumber string `gorm:"type:text(256);comment:'备案号'" json:"record_number"`
}

// SelectAllSetup /查询设置
func (t *Setup) SetupContent() Setup {
	setup := Setup{}
	err := Db.Select("desc", "blog_name", "blog_icon", "record_number").Where("id = ?", 100).Find(&setup).Error
	if err != nil {
		t.SteCodeMsg(errmsg.ERROR)
		return setup
	}
	return setup
}

// EditSetup /编辑设置
func (t *Setup) EditSetup() bool {
	err := Db.Model(&t).Where("id = ? ", 100).Omit("Id").Updates(t).Error
	if err != nil {
		return false
	}
	return true
}
